package com.easy.customer.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.easy.common.bean.CustomerContacts;
import com.easy.common.bean.Customers;
import com.easy.common.bean.Product;
import com.easy.common.service.ICustomerContactsService;
import com.easy.customer.mapper.CustomerContactsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerContactsService implements ICustomerContactsService {
    @Autowired
    CustomerContactsMapper customerContactsMapper;


    @Override
    public CustomerContacts insert(CustomerContacts contacts) {
        customerContactsMapper.insert(contacts);
        CustomerContacts result=this.getByID(contacts.getId());
        return result;
    }

    @Override
    public CustomerContacts update(CustomerContacts contacts) {
        customerContactsMapper.updateById(contacts);
        CustomerContacts result=this.getByID(contacts.getId());
        return result;
    }

    @Override
    public int delete(Integer id) {
        int result=customerContactsMapper.deleteById(id);
        return result;
    }


    @Override
    public int setPrimary(CustomerContacts contacts) {
        UpdateWrapper wrapper=new UpdateWrapper();
        if(contacts.getIs_primary()==0){
            wrapper.set("is_primary",1);
        }else{
            wrapper.set("is_primary",0);
        }
        wrapper.eq("id",contacts.getId());
        int result=customerContactsMapper.update(wrapper);
        return result;
    }

    @Override
    public CustomerContacts getByID(Integer id) {
        CustomerContacts result=customerContactsMapper.selectById(id);
        return result;
    }


}
